package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.PriceRules;
import com.lzm.ydpt.module.order.activity.PriceRulesActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.PriceRulesContract;
import com.lzm.ydpt.mvp.modelimpl.PriceRulesModelImpl;

/**
 * 类名称：PriceRulesPresenterImpl
 * 类描述：代理实现
 */
public class PriceRulesPresenterImpl extends BasePresenter implements PriceRulesContract.Presenter {

    private PriceRulesContract.View mView;
    private PriceRulesContract.Model mModel;

    public PriceRulesPresenterImpl(PriceRulesActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new PriceRulesModelImpl();
    }

    @Override
    public void onPriceRules(FormBodys formBodys) {
        mManager.http(mModel.onPriceRules(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<PriceRules>() {
            @Override
            public void onLoadingResult(BaseResponseBean<PriceRules> entity) {
                mView.onPriceRules(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onPriceRules"));
    }
}